<template>
  <view>
    <view class="address-box">
      <!-- 选择收货地址按钮 -->
      <view class="address-option-btn" v-if="JSON.stringify(address) === '{}'">
        <button type="primary" size="mini" @click="chooseAddress">请选择收货地址+</button>
      </view>
      
      <!-- 收货地址 -->
      <view class="user-address" v-else>
        <view class="address-top">
          <text>收货人：{{address.userName}}</text>
          <view class="tel">
            <text>电话：{{address.telNumber}}</text>
            <uni-icons type="right" size="15"></uni-icons>
          </view>
        </view>
        <view class="address-bottom">
          <view class="address-detail">收货地址：</view>
          <view>{{addrstr}}</view>
        </view>
      </view>
      
      <!-- 收货地址底边框 -->
      <view class="address-bd-bottom">
        <image src="/static/cart_border@2x.png"></image>
      </view>
    </view>
  </view>
</template>

<script>
  import {mapState, mapMutations, mapGetters} from 'vuex'
  export default {
    name:"my-address",
    data() {
      return {
        // addressList: {}
      };
    },
    methods: {
      ...mapMutations('m_user', ['updataAddress']),
      // 选择收货地址
      async chooseAddress() {
        const [err, succ] = await uni.chooseAddress().catch(err => err)
        
        if(err == null && succ.errMsg == "chooseAddress:ok") {
          this.updataAddress(succ)
        }
      }
    },
    computed: {
      ...mapState('m_user', ['address']),
      ...mapGetters('m_user', ['addrstr'])
    },
  }
</script>

<style lang="scss">
.address-box {
  width: 100%;
  .address-option-btn {
    height: 200rpx;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .user-address {
    padding: 20rpx 10rpx;
    font-size: 26rpx;
    .address-top {
      display: flex;
      justify-content: space-between;
      .tel {
        display: flex;
        justify-content: space-between;
      }
    }
    .address-bottom {
      margin-top: 20rpx;
      display: flex;
      .address-detail {
        white-space: nowrap;
        display: flex;
        align-items: center;
      }
    }
  }
  .address-bd-bottom {
    image {
      display: block;
      width: 100%;
      height: 10rpx;
    }
  }
}
</style>